package com.yanqu.road.server.cmd.cookboy.process2;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyActivityMgr;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COOK_BOY2_SEARCH_REQ, desc = "请求摊位信息")
public class CookBoy2GetRelationCmd extends AbstractCommand {

	int activityId;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		CookBoyProto.CookBoy2SearchReqMsg reqMsg = CookBoyProto.CookBoy2SearchReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = CookBoyActivityMgr.getOpenActivityInfo(activityId);
		if(activityInfo == null){
			ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
			return;
		}
		ret = CookBoyMgr.sendRelationMsg(activityId,player.getUserId());
	}

	@Override
	public void sendData(GamePlayer player) {
		if(ret != 0){
			CookBoyProto.CookBoy2CookerRespMsg.Builder respMsg = CookBoyProto.CookBoy2CookerRespMsg.newBuilder();
			respMsg.setRet(ret);
			player.sendPacket(Protocol.U_COOK_BOY2_SEARCH_REQ, respMsg);
		}
	}
}
